package com.shenhaofeng.app.utils;

import android.support.v7.widget.RecyclerView;


import com.shenhaofeng.app.adapter.BaseAdapter;

import java.util.List;

import rx.functions.Action1;

/**
 * 适配器助手
 * Created by Administrator on 2016/3/31.
 */
public class AdapterHelper {

    /**
     * 创建一个action，用于快速添加适配器数据
     *
     * @param adapter
     * @param <T>
     * @return
     */
    public static <T> Action1<T> add(final BaseAdapter<T, ? extends RecyclerView.ViewHolder> adapter) {
        return new Action1<T>() {
            @Override
            public void call(T t) {
                adapter.add(t);
            }
        };
    }


    /**
     * 创建一个action，用于快速添加适配器数据
     * @param adapter
     * @param <T>
     * @return
     */
    public static <T> Action1<List<T>> addAll(final BaseAdapter<T, ? extends RecyclerView.ViewHolder> adapter) {
        return new Action1<List<T>>() {
            @Override
            public void call(List<T> ts) {
                adapter.addAll(ts);
            }
        };
    }


}
